'''
Created on 2009-12-6

@author: jamiesun
'''
#coding:utf-8
from google.appengine.ext import webapp
from google.appengine.api import urlfetch 
import urllib,logging,sys
from google.appengine.api import users
class JavaeyeHandler(webapp.RequestHandler):
    target_url = "http://api.javaeye.com/api/twitters/create"
    def get(self):
        title = self.request.get("title")
        url = self.request.get("url")
        
        zdata = {"body":"%s %s"%(title.encode('utf-8'),url.encode("utf-8")),
                "via":"Google reader"
                }
        zheaders = {'Authorization':'Basic amFtaWVzdW46NTk0MTIz',
                   'User-Agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
                 }

        try:
            urlfetch.fetch(url=self.target_url,
                            payload=urllib.urlencode(zdata),
                            method=urlfetch.POST,
                            headers=zheaders)
            self.response.out.write("<script>window.close();</script>")
        except:
            info = sys.exc_info()
            logging.error("javaeye request error %s %s"%(info[0],info[1]))
            self.response.out.write("<script>window.close();</script>")
        